package org.anyin.gitee.cloud.center.upms.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.anyin.gitee.cloud.center.upms.mapper.SysRoleMapper;
import org.anyin.gitee.cloud.center.upms.model.SysRole;
import org.anyin.gitee.cloud.lib.core.enums.DelFlgEnum;
import org.anyin.gitee.cloud.lib.core.web.BaseRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SysRoleRepository extends BaseRepository<SysRoleMapper, SysRole> {

    public SysRole getByName(String roleName){
        QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
        wrapper.eq("role_name", roleName);
        wrapper.eq("del_flg", DelFlgEnum.NORMAL.getCode());
        return baseMapper.selectOne(wrapper);
    }

    public SysRole getByTitle(String roleTitle){
        QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
        wrapper.eq("role_title", roleTitle);
        wrapper.eq("del_flg", DelFlgEnum.NORMAL.getCode());
        return baseMapper.selectOne(wrapper);
    }

    public Page<SysRole> page(Page<SysRole> page, String roleName){
        List<SysRole> list = baseMapper.page(page, roleName);
        page.setRecords(list);
        return page;
    }
}
